package com.example.fw;

import java.util.List;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.ui.Select;

public abstract class  WebDriverHelperBase extends HelperBase {


	protected WebDriver driver;
	
	public WebDriverHelperBase(ApplicationManager manager){
		super(manager);
		this.driver = manager.getDriver();
	}

	protected void type(By locator, String text) {
		if (text != null){
		driver.findElement(locator).clear();
		driver.findElement(locator).sendKeys(text);
		}
	}

	protected void click(By locator) {
		driver.findElement(locator).click();
	}

	protected void selectByText(By locator, String text) {
		if (text != null){
		Select select = new Select(driver.findElement(locator));
	    List<WebElement> list = select.getOptions();
	    for (WebElement option : list) {
	       	String fullText = option.getText();
	       	if (fullText.contains(text)) {
	       		select.selectByVisibleText(fullText);
//	       		return 1;
	       		}
	    	}
//	    return 0; //can't find element_value. To include in the test report. How?
		}
	}
		
}
